let app = getApp();
Page({
  data: {
    isSubmit: false,
    warn: "",
    name:"",
    school:"",
    phone: "",
    sex: "男",
    userInfo:app.getuserInfo
  },
  formSubmit: function (e) {
    console.log('form发生了submit事件，携带数据为：', e.detail.value);
    let { phone, sex, name, school} = e.detail.value;
    if (!phone || !name || !school) {
      this.setData({
        warn: "请填写完所有信息！",
        isSubmit: true
      })
      wx.showToast({
        title: "请填写完所有信息！",
        icon: 'none',
        duration: 2000
      })
      return;
    }
    this.setData({
      warn: "",
      isSubmit: true,
      name,
      school,
      phone
    }),
      // 这里修改成跳转的页面
      wx.request({
      url: 'http://tv.tvata.com:10248/host/kzucqilv/index.php/user/api',
        data: {
          "action": "enterAct",
          "actId":"12",
          "type": "wx",
          "name_cn":name,
          "school":school,
          "phone": phone

        },
        headers: { 'Content-Type': 'application/json' },
        success: function (res) {
          console.log("===data===" + JSON.stringify(res.data));
          if (res.data.code == 1) {
            wx.showToast({
              title: '报名成功',
              icon: 'success',
              duration: 3000,
              success:wx.navigateTo({
                url: '../../pages/connection/connection',
              })
            })
          } else {
            wx.showToast({
              title: res.data.msg,
              icon: 'fail',
              duration: 2000
            })
          }
        }
      })

  },
  formReset: function () {
    console.log('form发生了reset事件')
  },
  onLoad: function () {
    var that = this
    wx.request({

      url: 'http://tv.tvata.com:10248/host/kzucqilv/index.php/photo/api',  
      data:{
        action:'show',
        id:'12'

      },

      headers: {   'Content-Type':  'application/json'   },

      success:  function  (res) {
        that.setData({
          activity: res.data.photo,
          activityList:res.data.photo.photolist,
        })
        }
     }),
      wx.getUserInfo({
        success: function (res) {
          var userInfo = res.userInfo
          var nickName = userInfo.nickName
          var avatarUrl = userInfo.avatarUrl
          var gender = userInfo.gender //性别 0：未知、1：男、2：女
          var province = userInfo.province
          var city = userInfo.city
          var country = userInfo.country
        }
        
      })
      
     },
    ename:function(e){
      this.setData({
        ename: e.detail.value
      })
    }
})
